#include "stdafx.h"

#include "util/check_framebuffer.h"
#include "core/logger.h"
#include "core/kernel.h"
#include "core/event.h"

namespace natrium {
	namespace util {
		CheckFramebuffer::CheckFramebuffer() {
			GLenum status;

			status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

			switch (status) {
			case GL_FRAMEBUFFER_COMPLETE:
				//it's ok
				break;

			case GL_FRAMEBUFFER_UNSUPPORTED:
				gLog.error() << "[util::CheckFramebuffer] Framebuffer format not supported"; //not supported on the current hardware, choose another
				break;

			case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
				gLog.error() << "[util::CheckFramebuffer] Incomplete framebuffer attachment";
				break;

			case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
				gLog.error() << "[util::CheckFramebuffer] Missing framebuffer attachment";
				break;

			case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
				gLog.error() << "[util::CheckFramebuffer] Incomplete layer target";
				break;

			default:
				gLog.fatal() << "[util::CheckFramebuffer] FATAL -- Invalid framebuffer format"; //not supported -- programming error, will fail on all hardware
				core::EventChannel chan;
				chan.broadcast(core::Kernel::StopEvent()); //shut everything down
			};
		}
	}
}